<?php
	//timer pengecekan load page...
	include("timer.php");
	$_start_timer = get_microtime();
	
	require_once("protect1.php"); 
	require_once("connect.php");
	require_once("settings.php");

	// $pilih=mysql_select_db("uwika_krs",$conn);
	$pdo->query("USE uwika_krs");
	
	// $mkjur='mk';
?>

<STYLE type=text/css>.blank {
	FONT-SIZE: 0px; WIDTH: 0px; HEIGHT: 0px
}
TD {
	FONT-SIZE: 12px; COLOR: #000000; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif
}
INPUT {
	FONT-SIZE: 12px; COLOR: #000000; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif
}
.present {
	FONT-WEIGHT: bold; BACKGROUND-COLOR: #dee5ec
}
.h1 {
	FONT-WEIGHT: bold; FONT-SIZE: 12px; COLOR: #ffffff
}
.d1 {
	COLOR: #c0c0c0
}
.link {
	FONT-WEIGHT: bold; FONT-SIZE: 12px; CURSOR: hand; COLOR: #ffffff; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; TEXT-DECORATION: none
}
.footer {
	FONT-WEIGHT: normal; FONT-SIZE: 10px; COLOR: #000000; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; TEXT-DECORATION: none
}
.footer1 {
	FONT-WEIGHT: bold; FONT-SIZE: 10px; BACKGROUND-IMAGE: url(chat/images/menu_b.gif); CURSOR: default; COLOR: #000000; BORDER-BOTTOM: 0px
}
.header {
	FONT-WEIGHT: bold; FONT-SIZE: 10px; BACKGROUND-IMAGE: url(chat/images/menu_h.gif); CURSOR: default; COLOR: #000000; BORDER-BOTTOM: 0px
}
.textcol {
	FONT-SIZE: 12px; COLOR: #2378d5; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif
}
body,td,th {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 11pt;
	color: #FFFFFF;
}
body {
	background-image: url(bg.jpg);
	background-repeat: repeat;
}
a:link {
	color: #FFFFFF;
	text-decoration: none;
}
a:visited {
	text-decoration: none;
	color: #FFFFFF;
}
a:hover {
	text-decoration: underline;
	color: #001C89;
}
a:active {
	text-decoration: none;
	color: #011B89;
}
</STYLE>


<title>:: VIEW KRS ::</title><table width="780" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td bgcolor="7e96dc">&nbsp;</td>
  </tr>
  <tr>
    <td><img src="images/bannerAtas.jpg" alt="image" width="780" height="200" /></td>
  </tr>
  <tr>
    <td bgcolor="3a5db1">
	<?php
		//ganti dengan yg otomatis
		//$_select_sesi = $_GET["sel_sesi"];
		//$_select_periode = $_GET["sel_periode"];
		
		$_select_sesi = $_global_settings['semester']->value;
		$_select_periode = $_global_settings['tahun_ajaran']->value;
		
	?>
		<BR><div align = center>
		Berikut dibawah ini adalah daftar mata kuliah yang sudah anda daftarkan pada KRS :
		<br>
		Semester : <b> <?php echo $_select_sesi; ?></b><br>
		Periode : <b> <?php echo $_select_periode; ?>
		</b><br><BR>
		<table width="75%" border="1" align=center cellpadding=0 cellspacing=0>
		<tr>
		<td width="5%" bgcolor="#001E8C"><center>K O D E</center></td>
		<td width="20%" bgcolor="#001E8C"><center>N A M A &nbsp; M A T A  &nbsp; K U L I A H</center></td>
		<td width="5%" bgcolor="#001E8C"><center>STATUS</center></td>
		<td width="3%" bgcolor="#001E8C"><center>SKS</center></td>
		</tr>

	<?php

	$sql = "SELECT registrasi.kodemk, mk.nama, mk.sks, registrasi.sesi, registrasi.status, registrasi.validasi, registrasi.hari, 
			registrasi.mulaipukul, registrasi.selesaipukul 
			FROM registrasi, mk where sesi=:select_sesi and periode=:select_periode and nrp=:reg_uname and registrasi.kodemk = mk.kodemk";
	$stmt = $pdo->prepare($sql);
	$stmt->execute(array(':select_sesi' => $_select_sesi
							,':select_periode' => $_select_periode
							,':reg_uname' => $reg_uname )); //reg jurusan dari protect1.php
	$jmlsks=0;
	while($_data = $stmt->fetch(PDO::FETCH_OBJ)){ //fetch data to stdclass object		

		if (empty($_data->kodemk)) {
			break;
		}
		$sql2="select hari, mulaipukul, selesaipukul FROM penawaran where kodemk=:kodemk and jurusan=:reg_jurusan";
		$stmt2 = $pdo->prepare($sql2);
		$stmt2->execute(array(':kodemk' => $_data->kodemk
							,':reg_jurusan' => $reg_jurusan )); //reg jurusan dari protect1.php
		$_data2 = $stmt2->fetch(PDO::FETCH_OBJ);
		//_data -> lama
		//_data2 -> baru
		//gtw buat apa,.. ngikut aja.. kyknya update.. pdhl setelah dipindah ke riris data registrasi ttng waktu , tidak dibutuhkan
		if($_data->hari != $_data2->hari ){
			$sql_update = "UPDATE registrasi SET hari=:haribaru WHERE nrp=:reg_uname AND kodemk=:kodemk";
			$stmt_update = $pdo->prepare($sql_update);
			$stmt_update->execute(array(':haribaru' => $_data2->hari
								,':reg_uname' => $reg_uname
								,':kodemk' => $_data->kodemk ));
		}	
		if (($_data->hari == $_data2->hari) && ($_data->mulaipukul != $_data2->mulaipukul)) {
			$sql_update = "UPDATE registrasi set mulaipukul=:mulaibaru where nrp=:reg_uname and kodemk=:kodemk";
			$stmt_update = $pdo->prepare($sql_update);
			$stmt_update->execute(array(':mulaibaru' => $_data2->mulaipukul
								,':reg_uname' => $reg_uname
								,':kodemk' => $_data->kodemk ));
		}
		if (($_data->hari == $_data2->hari) && ($_data->selesaipukul != $_data2->selesaipukul)) {
			$sql_update = "update registrasi set selesaipukul=:selesaibaru where nrp=:reg_uname and kodemk=:kodemk";
			$stmt_update = $pdo->prepare($sql_update);
			$stmt_update->execute(array(':selesaibaru' => $_data2->selesaipukul
								,':reg_uname' => $reg_uname
								,':kodemk' => $_data->kodemk ));
		}
		
		if ($_data->validasi == 0) {	
			if (date("Y-m-d H:i:s") >= "2012-08-30 01:00:01" && date("Y-m-d H:i:s") <= "2013-09-14 11:59:59"){ // batasan waktu (jam 30 agust 13.00.01 - 14 sept 23.59.59)
//				echo "<tr><td><center><a href=\"hapus.php?nrp=".$reg_uname."&kodemk=".$_data->kodemk."&sesi=".$_data->sesi."&periode=".$_select_periode."\"> ".$_data->kodemk." </center></td>";
				echo "<tr><td><center><a href=\"hapus.php?kodemk=".$_data->kodemk."\"> ".$_data->kodemk." </center></td>";
			} else {
				echo "<tr><td><center>".$_data->kodemk."</center></td>";	
			}
		} else {
			echo "<tr><td><center>".$_data->kodemk."</center></td>";
		}
		?>
			<td> <?php echo $_data->nama; ?></td>
			<td><center> <?php echo $_data->status; ?> </center></td>
			<td><center> <?php echo $_data->sks; ?> </center></td>
			</tr>
		<?php
		$jmlsks = $jmlsks + $_data->sks; 
	}
	?>
		</td></td><td width=5%></td></tr></table>
		<table width="75%" border="0">
		<tr><td width="30%"></td><td><p align="right">TOTAL SKS : </p></td><td width=10%><center>
	<?php
	if ($jmlsks > 24) {
		?>
			<b><font color="#FF0000">$jmlsks</font></b>
			<br>
			</center></td><td width=5%></td></tr>
			</table>
			<center><b><font color=#FF0000>Jumlah SKS yang anda ambil tidak boleh melebihi 24 SKS !!!</font></b></center>
		<?php
	} else {
		echo $jmlsks;
	}
	?>
		</center</td></tr>
		</table>
		<br>
	<?php
	if ($validasi==0) {
		echo "*** Klik pada kode mata kuliah untuk membatalkan mata kuliah dalam KRS anda ***";
	} else {
		echo "*) KRS ini sudah disetujui oleh dosen wali. Selamat menempuh perkuliahan. Sukses !";
	}
	
	echo "&nbsp;";
	echo "<br><br>";
	
	$sql = "select sks,ips,toleransi from ips where nrp = :reg_uname";
	$stmt = $pdo->prepare($sql);
	$stmt->execute(array(':reg_uname' => $reg_uname )); //reg jurusan dari protect1.php
	$_data = $stmt->fetch(PDO::FETCH_OBJ);
	//list($sks,$ips,$toleransi) = $row;
	
	$sql = "select sum(sks) as sksdlmkrs from registrasi where nrp = :reg_uname";
	$stmt2 = $pdo->prepare($sql);
	$stmt2->execute(array(':reg_uname' => $reg_uname )); //reg jurusan dari protect1.php
	$_data2 = $stmt2->fetch(PDO::FETCH_OBJ);
	//list($sksdlmkrs) = $row;

	if ($_data->ips < 1.500) {
		$limitsksx = 12;
	}
	if (($_data->ips >= 1.500) and ($_data->ips < 1.750)) {
		$limitsksx = 14;
	}
	if (($_data->ips >= 1.750) and ($_data->ips < 2.000)) {
		$limitsksx = 16;
	}
	if (($_data->ips >= 2.000) and ($_data->ips < 2.250)) {
		$limitsksx = 18;
	}
	if (($_data->ips >= 2.250) and ($_data->ips < 3.000)) {
		$limitsksx = 21;
	}
	if ($_data->ips >= 3.000) {
		$limitsksx = 24;
	}
	/*
		mengubah disini YULIUS H
		untuk siswa angkatan baru agar tidak 12 SKS
	*/
	$pengecekan = $reg_uname[3].$reg_uname[4];
	if ($pengecekan == 12)
	{
		$limitsksx = 24;
	}
	// Sampai disini saja!

	echo "<table width=75%>";
	$sql = "SELECT nama FROM biodata WHERE nrp = :reg_uname ";
	$stmt3 = $pdo->prepare($sql);
	$stmt3->execute(array(':reg_uname' => $reg_uname )) or die("ERROR: " . implode(":", $stmt->errorInfo())); //reg jurusan dari protect1.php
	$_data3 = $stmt3->fetch(PDO::FETCH_OBJ);
	
	?>
				<tr><td width=20%>N R P</td><td>:</td><td width=83%><?php echo $reg_uname; ?></td></tr>
				<tr><td width=20%>N A M A</td><td>:</td><td width=83%><?php echo $_data3->nama; ?></td></tr>
				<tr><td width=20%>Nilai IPS terakhir </td><td>:</td><td width=83%><?php echo $_data->ips; ?></td></tr>
				<tr><td>Limit SKS anda</td><td>:</td><td><?php echo $limitsksx; ?> SKS</td></tr>
				<tr><td>Toleransi SKS anda</td><td>:</td><td><?php echo $_data->toleransi; ?> SKS</td></tr>
				<tr><td>Sisa Limit SKS anda</td><td>:</td><td><?php echo $limitsksx + $toleransi - $_data2->sksdlmkrs; ?> SKS</td></tr>
			</table>
		</div><br>
	<?php
	/*PENAMBAHAN TEMPAT untuk TANDA TANGAN*/
	?>
		<div align=center>
			<table border=1 width=75%>
				<tr>
					<td width=150 align=center>DOSEN WALI</td>
					<td width=150 align=center>BAA</td>
					<td width=150 align=center>MAHASISWA</td>
				</tr>
				<tr height=75>
					<td width=150 align=center>&nbsp;</td>
					<td width=150 align=center>&nbsp;</td>
					<td width=150 align=center>&nbsp;</td>
				</tr>
				<tr>
					<td width=150 align=center>(__________________)</td>
					<td width=150 align=center>(__________________)</td>
					<td width=150 align=center><?php echo $reg_uname; ?></td>
				</tr>
			</table>
			<font size=2><strong><i>
				*) Dibuat Rangkap 2 (Dua): (1)DOSEN WALI, (2)BAA, dan (3)MAHASISWA <br>
				**) WAJIB Membubuhkan Tanda Tangan Di Tiap Kolom Yang Disiapkan
			</i></strong></font>
		</div>
	<?php
	/*
	echo "<BR> <div align = center>";
	echo "Berikut dibawah ini adalah daftar mata kuliah yang sudah anda daftarkan pada KRS :";
	echo "<br>";
	echo "Semester : <b> " . $_select_sesi;
	echo "</b><br>";
	echo "Periode : <b> " . $_select_periode;
	echo "</b><br><BR>";
	echo "<table width=\"75%\" border=\"1\" align=center cellpadding=0 cellspacing=0>";
	echo "<tr>";
	echo "<td width=\"5%\" bgcolor=\"#001E8C\"><center>K O D E</center></td>";
	echo "<td width=\"20%\" bgcolor=\"#001E8C\"><center>N A M A &nbsp; M A T A  &nbsp; K U L I A H</center></td>";
	echo "<td width=\"5%\" bgcolor=\"#001E8C\"><center>STATUS</center></td>";
	echo "<td width=\"3%\" bgcolor=\"#001E8C\"><center>SKS</center></td>";
	echo "</tr>";
	
	$sqlstr="delete from registrasi where sks=0";
	//$hasil=mysql_query($sqlstr);
	$sqlstr="select registrasi.kodemk, $mkjur.nama, $mkjur.sks, registrasi.sesi, registrasi.status, registrasi.validasi, registrasi.hari, registrasi.mulaipukul, registrasi.selesaipukul from registrasi,$mkjur where sesi='$_select_sesi' and periode='$_select_periode' and nrp='$reg_uname' and registrasi.kodemk=$mkjur.kodemk";
	$hasil=mysql_query($sqlstr);
	$row = mysql_fetch_row($hasil);
	$jmlsks=0;
	do {
		list($kodemkx,$nama,$sks,$sesi,$status,$validasi,$harilama,$mulailama,$selesailama) = $row;
		if (empty($kodemkx)) {
		break;
		}
		$sqlstr2="select hari,mulaipukul, selesaipukul from penawaran where kodemk='$kodemkx' and jurusan='$reg_jurusan'";
		$updatejadwal=mysql_query($sqlstr2);
		list($haribaru,$mulaibaru,$selesaibaru) = mysql_fetch_row($updatejadwal);
		if ($harilama != $haribaru) {
			$sqlstr="update registrasi set hari='$haribaru' where nrp='$reg_uname' and kodemk='$kodemkx'";
			$updatejadwal=mysql_query($sqlstr);
		}
		if (($harilama == $haribaru) && ($mulailama != $mulaibaru)) {
			$sqlstr="update registrasi set mulaipukul='$mulaibaru' where nrp='$reg_uname' and kodemk='$kodemkx'";
			$updatejadwal=mysql_query($sqlstr);
		}
		if (($harilama == $haribaru) && ($selesailama != $selesaibaru)) {
			$sqlstr="update registrasi set selesaipukul='$selesaibaru' where nrp='$reg_uname' and kodemk='$kodemkx'";
			$updatejadwal=mysql_query($sqlstr);
		}
		if ($validasi==0) {	
			if (date("Y-m-d H:i:s") >= "2012-08-30 01:00:01" && date("Y-m-d H:i:s") <= "2012-09-14 11:59:59") // batasan waktu (jam 30 agust 13.00.01 - 14 sept 23.59.59)
//			if (date("Y-m-d H:i:s") >= "2012-08-29 13:00:01" && date("Y-m-d H:i:s") <= "2012-09-13 11:59:59") // batasan waktu
			echo "<tr><td><center><a href=\"hapus.php?nrp=$reg_uname&kodemk=$kodemkx&sesi=$sesi&periode=$_select_periode\"> $kodemkx </center></td>";
		   else
			echo "<tr><td><center>$kodemkx</center></td>";	
		} else {
			echo "<tr><td><center>$kodemkx</center></td>";
		}
		echo "<td> $nama </td>";
		echo "<td><center> $status </center></td>";
		echo "<td><center> $sks </center></td>";
		echo "</tr>";
		$jmlsks=$jmlsks + $sks; 
	} while ($row=mysql_fetch_row($hasil));

	echo "</td></td><td width=5%></td></tr></table>";
	echo "<table width=\"75%\" border=\"0\">";
	echo "<tr><td width=\"30%\"></td><td><p align=\"right\">TOTAL SKS : </p></td><td width=10%><center>";
	if ($jmlsks > 24) {
		echo "<b><font color=\"#FF0000\">$jmlsks</font></b>";
		echo "<br>";
		echo "</center></td><td width=5%></td></tr>";
		echo "</table>";
		echo "<center><b><font color=#FF0000>Jumlah SKS yang anda ambil tidak boleh melebihi 24 SKS !!!</font></b></center>";

	} else {
		echo $jmlsks;
	}
	echo "</center</td></tr>";
	echo "</table>";
	echo "<br>";
	if ($validasi==0) {
		echo "*** Klik pada kode mata kuliah untuk membatalkan mata kuliah dalam KRS anda ***";
	} else {
		echo "*) KRS ini sudah disetujui oleh dosen wali. Selamat menempuh perkuliahan. Sukses !";
	}
	echo "&nbsp;";
	echo "<br><br>";
	$sqlstr="select sks,ips,toleransi from ips where nrp='$reg_uname'";
	$hasil=mysql_query($sqlstr);
	$row = mysql_fetch_row($hasil);
	list($sks,$ips,$toleransi) = $row;
	$sqlstr="select sum(sks) from registrasi where nrp='$reg_uname'";
	$hasil=mysql_query($sqlstr);
	$row = mysql_fetch_row($hasil);
	list($sksdlmkrs) = $row;

	if ($ips < 1.500) {
		$limitsksx = 12;
	}
	if (($ips >= 1.500) and ($ips < 1.750)) {
		$limitsksx = 14;
	}
	if (($ips >= 1.750) and ($ips < 2.000)) {
		$limitsksx = 16;
	}
	if (($ips >= 2.000) and ($ips < 2.250)) {
		$limitsksx = 18;
	}
	if (($ips >= 2.250) and ($ips < 3.000)) {
		$limitsksx = 21;
	}
	if ($ips >= 3.000) {
		$limitsksx = 24;
	}
	//
	//	mengubah disini YULIUS H
	//	untuk siswa angkatan baru agar tidak 12 SKS
	//
	$pengecekan = $reg_uname[3].$reg_uname[4];
	if ($pengecekan == 12)
	{
		$limitsksx = 24;
	}
	// Sampai disini saja!
	echo "<table width=75%>";
	$sqlstr="SELECT biodata.nama FROM security,biodata where security.username='$reg_uname' and biodata.nrp=security.username";
	$hasil=mysql_query($sqlstr);
	$row = mysql_fetch_row($hasil);
	list($namamhs) = $row;
	echo "<tr><td width=20%>N R P</td><td>:</td><td width=83%>$reg_uname</td></tr>";
	echo "<tr><td width=20%>N A M A</td><td>:</td><td width=83%>$namamhs</td></tr>";
	echo "<tr><td width=20%>Nilai IPS terakhir </td><td>:</td><td width=83%>$ips</td></tr>";
	echo "<tr><td>Limit SKS anda</td><td>:</td><td>$limitsksx SKS</td></tr>";
	echo "<tr><td>Toleransi SKS anda</td><td>:</td><td>$toleransi SKS</td></tr>";
	echo "<tr><td>Sisa Limit SKS anda</td><td>:</td><td>";
	echo $limitsksx+$toleransi-$sksdlmkrs;
	echo " SKS</td></tr></table>";
	echo "</div><br>";
	//PENAMBAHAN TEMPAT untuk TANDA TANGAN//
	echo "<div align=center>";
	echo "	<table border=1 width=75%>";
	echo "		<tr>";
	echo "			<td width=150 align=center>DOSEN WALI</td>";
	echo "			<td width=150 align=center>BAA</td>";
	echo "			<td width=150 align=center>MAHASISWA</td>";
	echo "		</tr>";
	echo "		<tr height=75>";
	echo "			<td width=150 align=center>&nbsp;</td>";
	echo "			<td width=150 align=center>&nbsp;</td>";
	echo "			<td width=150 align=center>&nbsp;</td>";
	echo "		</tr>";
	echo "		<tr>";
	echo "			<td width=150 align=center>(__________________)</td>";
	echo "			<td width=150 align=center>(__________________)</td>";
	echo "			<td width=150 align=center>($reg_uname)</td>";
	echo "		</tr>";
	echo "	</table>";
	echo "	<font size=2><strong><i>";
	echo "		*) Dibuat Rangkap 2 (Dua): (1)DOSEN WALI, (2)BAA, dan (3)MAHASISWA <br>";
	echo "		**) WAJIB Membubuhkan Tanda Tangan Di Tiap Kolom Yang Disiapkan";
	echo "	</i></strong></font>";
	echo "</div>";
	*/
	//stop here, bawahnya tambahan
	/*
	echo "<hr>";
	echo "Jika anda kenal dengan orang-orang dibawah ini, sampaikan kepada mereka bahwa registrasi KRS mereka tidak boleh melebihi 24 SKS.";
	echo "<br>";
	echo "Untuk informasi lebih lanjut, silahkan anda hubungi Direktur Akademis Universitas, Bapak Muliadi Tedja Sukmana. Terimakasih.";
	echo "<br><br>";
	$sqlstr="select ips.ips,registrasi.nrp,sum(registrasi.sks),biodata.nama from registrasi, biodata, ips where biodata.nrp=registrasi.nrp and ips.nrp=registrasi.nrp group by registrasi.nrp order by registrasi.nrp";
	$hasil=mysql_query($sqlstr);
	$row = mysql_fetch_row($hasil);
	$counter=0;
	do {
		list($ips, $nrp,$sks, $nama) = $row;
		if ($sks > 24) {
			$counter++;
			echo $nrp . "-" . $nama . " (" . $ips . ") " . $sks . "<br>";
		}
	} while ($row=mysql_fetch_row($hasil));
    echo "Jumlah Total : " . $counter;
	*/

	include("footer.php");
?>
	&nbsp;</td>
  </tr>
  <tr>
    <td bgcolor="7e96dc"><div align="center">
	<footer id="main">
	  <a href="http://www.widyakartika.ac.id/perpustakaan">Perpustakaan Online</a> | <a href="http://krs.widyakartika.ac.id/">KRS Online</a>
	  <br \>
	  Copyright &copy; 2012. <a href="http://www.widyakartika.ac.id">Universitas Widya Kartika</a> & <a href="#">Labkom ICT</a> - All rights reserved
	  <p>
		<?php
			$_finish_timer = get_microtime();
			echo 'Page generated in '.round(($_finish_timer - $_start_timer), 4).' seconds.';
		?>
	</footer>
	</div></td>
  </tr>
</table>
